home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 614 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. From: steven2@salesbook.com (Steve Nutt)
  2. Message-ID: <4hb90g$apu@post.acadia.net>
  3. X-Original-Date: Sun, 03 Mar 1996 07:28:33 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 03 Mar 96 21:22:41 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: overriding functions a la Stroustrup allowed?
  9. Organization: DET
  10. References: <4h4hmr$41o@news.rwth-aachen.de>
  11. Reply-To: steven2@salesbook.com
  12. X-Newsreader: Forte Free Agent 1.0.82
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMToNueEDnX0m9pzZAQHcQwGAib5Z6kqDGDiSKx6bdY5Wc+LsarRzHmef
  15.     8BoUtj+zAlDHH2FrSvrotupiR5oeugFh
  16.     =AqKi
  17.  
  18. fischer@Informatik.RWTH-Aachen.DE (Rainer Fischer) wrote:
  19.  
  20. >In "Bjarne Stroustrup, The C++ programming language (german translation)"
  21. >I found an example, which looks like this:
  22.  
  23. >struct base {
  24. >  base *next;
  25. >  static base *list;
  26.  
  27. >  base() {next = list; list = this};
  28.  
  29. >  virtual void function() = 0;
  30. >  // ...
  31. >};
  32.  
  33. >class derived : public base {
  34. >  // ...
  35. >public:
  36. >  void function();
  37. >  // ...
  38. >};
  39.  
  40.  
  41. >Two questions:
  42.  
  43. >1)  Does function() in class derived really override function() in base?
  44. >    Does the declaration in derived really say that function is not pure
  45. >    virtual and not virtual at all? I get a linker error-message, when I
  46. >    use such a construction without defining the overriding function, but
  47. >    neither a compiler error nor a warning. Is this correct?
  48.  
  49. I'm not totally sure what you are asking here, but it all looks OK.
  50.  
  51. The virtualness of function is inherited from base. It perhaps  makes
  52. the code easier to understand if the virtual keyword is added to
  53. derived.
  54.  
  55. >2)  What happens, when the very first object is created with a class
  56. >    derived from base? The constructor of base assignes list to next, but
  57. >    list is not yet initialized; so rubbish may be assigned to next. Is
  58. >    there no need to initialize list first, e.g. base *base::list = 0; some-
  59. >    where outside of base? I get a compiler error, if I don't do it.
  60.  
  61. You should get a linker error rather than a compiler error if you
  62. don't.
  63.  
  64. >Thanks in advance for any help,
  65.  
  66. >Rainer Fischer.
  67. ---
  68. [ To submit articles: try just posting with your news-reader.
  69.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  70.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  71.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  72.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  73. ]
  74.